<template>
  <div>
    <div id="g_top" class="m-top">&nbsp;</div>
    <div id="g_nav" class="m-subnav">&nbsp;</div>
    <div class="piaylist" v-if="viewFlag">
      <div class="v_hd2">
        <h3>{{ title }}</h3>
        <a href="javascript:;" class="btn" @click="flag = !flag">
          <i class="myicon">选择分类</i>
        </a>
        <div class="u-btn">
          <a href="#" class="a1" data-order="hot">热门</a>
        </div>
      </div>
      <!-- 分类盒子 -->
      <div class="n-sltlyr d-flag n-sltlyr-show" v-show="flag">
        <div class="hd"><i class="icn"></i></div>
        <div class="bd">
          <dl
            class="f-cb"
            v-for="(item, W_index) in catlist_Data"
            :key="W_index"
          >
            <dt>
              <i :class="['n-icn', item.style]"></i>
              {{ item.name }}
            </dt>
            <dd>
              <span
                v-for="(item, index) in catlist_Data[W_index].list"
                :key="index"
              >
                <a
                  href="javascript:;"
                  class="s-fc1"
                  @click.stop="select_menu(item.name)"
                  >{{ item.name }}</a
                >
                <span class="line">|</span>
              </span>
            </dd>
          </dl>
        </div>
        <div class="ft"></div>
      </div>
      <!-- 列表 -->
      <Playlist_item :resPlaylist = 'playlistData' ></Playlist_item>
      <!-- 底部按钮 -->
      <div class="Pagination" v-if="playlistData.length">
        <el-pagination
          background
          layout="prev, pager, next"
          :total="100"
          :current-page="page_num"
          @current-change="Pagination"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { catlist } from "../../../network/discover"; //分类

import Playlist_item from "./playlist_ltem";
import { getPlaylist } from "../../../network/discover"; //歌单页面请求
export default {
  components: {
    Playlist_item
  },
  data() {
    return {
      title: "全部",
      limit: 35,
      page_num: 0,
      catlist_Data: [   //音乐菜单
        { list: [], name: "语种", style: "n-icn-71" },
        { list: [], name: "场景", style: "n-icn-7" },
        { list: [], name: "情感", style: "n-icn-8" },
      ],
      playlistData:[],  //歌单内容
      flag: false,
      viewFlag:true
    };
  },
  methods: {
     retard(){
          this.viewFlag = false
          this.$nextTick(() => {
              this.viewFlag = true
          })
      },
    select_menu(name) {
      //音乐菜单的选项
      this.$router.push({ path: "/home/discover/playlist",query: { cat: name },});
    },
    res_catlist() {   //音乐菜单内容的获取
      catlist().then(
        (res) => {
          res.data.sub.forEach((item) => {
            if (item.category == 0) {
              this.catlist_Data[0].list.push(item);
            }
            if (item.category == 2) {
              this.catlist_Data[1].list.push(item);
            }
            if (item.category == 3) {
              this.catlist_Data[2].list.push(item);
            }
          });
        },
        (err) => {
          console.log("分类请求失败");
        }
      );
    },
    Pagination(value) {   //分页菜单的选项
      this.$router.push({
        path: "/home/discover/playlist",
        query: {
          cat: this.title,
          limit: this.limit,
          offset: this.limit * value,
        },
      });
    },
    resPlayListData(cat ,limit , offset){   //
      getPlaylist(cat , limit , offset).then(res => {
           this.retard()
          this.playlistData = res.data.playlists
      },err => {
          console.log('歌单内容失败')
      })
    }
  },
  watch: {
    $route(to) {
      this.title = to.query.cat ? to.query.cat : "全部";
      this.page_num = this.$route.query.offset? this.$route.query.offset / 35 : 0;
      this.resPlayListData(this.title , this.limit , this.page_num*35)
    },
  },
  created() {
    this.title = this.$route.query.cat ? this.$route.query.cat : "全部";
    this.page_num = this.$route.query.offset ? this.$route.query.offset / 35: 0;
    this.res_catlist();
    this.resPlayListData(this.title , this.limit , this.page_num*35)
  },
  mounted() {
    var _this = this;
    document.addEventListener("click", function (e) {
      e.stopPropagation();
      if (
        e.target.className !== "n-sltlyr-show" &&
        e.target.className !== "myicon"
      ) {
        _this.flag = false;
      }
    });
  },
};
</script>

<style scoped>
.piaylist {
  width: 73%;
  min-height: 290px;
  margin: 0 auto;
  padding: 40px;
  background-color: #fff;
}
.v_hd2 {
  border-bottom: 2px solid #c10d0c;
  height: 40px;
}
h3 {
  display: block;
  font-size: 24px;
  font-weight: normal;
  padding: 0;
  margin: 0;
  float: left;
}
.u-btn {
  float: right;
  height: 29px;
  background-position: 0 0;
  border-radius: 3px;
  background: url("../../../assets/imgs/button.png") no-repeat;
}
.a1 {
  width: 46px;
  height: 29px;
  line-height: 29px;
  text-align: center;
  display: inline-block;
  color: wheat;
  font-size: 12px;
  font-family: Arial, Helvetica, sans-serif;
}
.Pagination {
  padding-left: 25%;
  margin-bottom: 20px;
}
.btn {
  display: inline-block;
  margin-left: 5px;
  font-size: 12px;
  font-weight: normal;
  background: url("../../../assets/imgs/button2.png");
  background-position: right -100px;
  overflow: hidden;
  height: 31px;
  line-height: 31px;
  text-align: center;
  padding: 0 5px 0 0;
}
.btn i {
  color: #0c73c2;
  padding: 0 10px 0 15px;
  background: url("../../../assets/imgs/button2.png") no-repeat;
  background-position: 0 -59px;
  display: inline-block;
  height: 31px;
  font-style: normal;
}

.m-top {
  position: relative;
  z-index: 100;
  height: 70px;
  box-sizing: border-box;
  background: #242424;
  border-bottom: 1px solid #000;
}
.m-subnav {
  z-index: 90;
  height: 35px;
  box-sizing: border-box;
  background-color: #c20c0c;
  border-bottom: 1px solid #a40011;
}
.n-sltlyr-show {
  display: block;
}
.n-sltlyr {
  position: absolute;
  top: 180px;
  left: 130px;
  z-index: 5;
  width: 720px;
}
.n-sltlyr .hd {
  height: 32px;
  border-bottom: 1px solid #e6e6e6;
}
.n-sltlyr .hd,
.n-sltlyr .bd,
.n-sltlyr .ft {
  background: url("https://s2.music.126.net/style/web2/img/sltlyr.png?ee26be7f868aa8a56281342cb35be84b")
    no-repeat;
}
.n-sltlyr .icn {
  position: absolute;
  top: 2px;
  left: 132px;
  display: inline-block;
  width: 24px;
  height: 11px;
  background: url("../../../assets/imgs/iconall.png") no-repeat;
  background-position: -48px 0;
  vertical-align: middle;
}
.n-sltlyr .bd {
  width: 700px;
  padding: 0 10px;
  background-position: -720px 0;
  background-repeat: repeat-y;
}

ul,
ol,
li,
dl,
dt,
dd {
  padding: 0;
  margin: 0;
}
.f-cb::after {
  clear: both;
  content: ".";
  display: block;
  height: 0;
  visibility: hidden;
}
.n-sltlyr dt {
  float: left;
  display: inline;
  width: 70px;
  margin: 0 -100px 0 26px;
  padding-top: 15px;
  border-right: 1px solid #e6e6e6;
  font-weight: bold;
  font-size: 12px;
  color: #333;
}
.n-sltlyr .n-icn {
  margin-right: 8px;
  margin-bottom: 4px;
}
.n-icn {
  display: inline-block;
  overflow: hidden;
  vertical-align: middle;
  background: url("../../../assets/imgs/icon.png") no-repeat;
}
.n-icn-71 {
  width: 23px;
  height: 23px;
  background-position: -20px -735px;
}
.n-icn-7 {
  width: 24px;
  height: 24px;
  background-position: 0 -88px;
}
.n-icn-8 {
  width: 24px;
  height: 24px;
  background-position: 0 -117px;
}
.n-sltlyr dd {
  margin-left: 96px;
  padding: 16px 15px 0 15px;
  border-left: 1px solid #e6e6e6;
  line-height: 24px;
  font-size: 12px;
}
.n-sltlyr dd a {
  white-space: nowrap;
}
.s-fc1 {
  color: #333;
}
.s-fc1:hover {
  text-decoration: underline;
}
.n-sltlyr dd .line {
  margin: 0 8px 0 10px;
  color: #d8d8d8;
}
.n-sltlyr .ft {
  height: 20px;
  background-position: -1440px -12px;
}
</style>